/*
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is
 *
 * java-concurrency-presentation:
 * concurrency presentation tutorial.
 *
 * The Initial Developer of the Original Code is
 * Marco Antonio Villalobos, Jr.
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): None.
 *
 * ***** END LICENSE BLOCK *****
 */

package presentation.concurrency.bad;

import presentation.concurrency.util.ContextSwitcher;

/**
 * Provides a class of mutable data.
 *
 * Contains one value, that is mutated by the incrementBy method.
 *
 * It has one accessor.
 */
public class Mutable {

    /** The value to be changed. */
    private double value = 0;

    /** A reference to its own context switcher. */
    private ContextSwitcher contextSwitcher = new ContextSwitcher();

    /**
     * Increment the value by the given parameter.
     *
     * @param v The value to increment by.
     */
    public void incrementBy(double v) {
        value+=v;
        contextSwitcher.forceSometimes();
    }

    /**
     * Retrieves the value.
     *
     * @return The value to retrieve.
     */
    public double getValue() {
        return value;
    }
}